home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / MakeWrite / MakeWrite Folder / MWParaDlog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  4.3 KB  |  218 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Paragraph style dialog
  3.  */
  4.  
  5. # include    "TransSkel.h"
  6.  
  7. # include    "MakeWrite.h"
  8.  
  9. # define    normalHilite    0
  10. # define    dimHilite        255
  11.  
  12. typedef enum        /* paragraph style dialog item numbers */
  13. {
  14.     paraOK = 1,
  15.     paraCancel,
  16.     paraEach,
  17.     paraBlank,
  18.     paraSmart,
  19.     paraMText,
  20.     paraPText,
  21.     paraQText,
  22.     paraLine1,
  23.     paraLine2,
  24.     pControlStaticText,
  25.     lControlStaticText,
  26.     markStaticText,
  27.     periodStaticText,
  28.     quoteStaticText,
  29.     outlineUserItem
  30. };
  31.  
  32.  
  33. /*
  34.  * Initialize paragraph style to default:  blank lines and lines
  35.  * beginning with whitespace initiate paragraphs,  line joining
  36.  * is smart, there's no explicit paragraph or page break marker.
  37.  */
  38.  
  39.  
  40. static ParaStyle    defStyle =  { false, true, true };
  41. static Str255        defPeriodStr = "\p.!?";
  42. static Str255        defQuoteStr = { 5, '"', '\'', 0xd3, 0xd5, ')' };
  43.  
  44.  
  45. /*
  46.  * Set the contents of a string using the contents of the 'STR '
  47.  * resource whose id is passed as strResId.
  48.  */
  49.  
  50. static void
  51. ResSetString (short strResId, StringPtr str)
  52. {
  53. StringHandle    hStr;
  54.  
  55.     hStr = GetString (strResId);
  56.     HLock ((Handle) hStr);
  57.     if ((*hStr)[0] > maxMarkLen)
  58.         (*hStr)[0] = maxMarkLen;
  59.     CopyString (*hStr, str);
  60.     HUnlock ((Handle) hStr);
  61.     ReleaseResource ((Handle) hStr);
  62. }
  63.  
  64.  
  65. void
  66. InitParaStyle (void)
  67. {
  68.     paraStyle = defStyle;
  69.     paraMark[0] = 0;
  70.     pageMark[0] = 0;
  71.     ResSetString (periodStrNum, periodStr);
  72.     ResSetString (quoteStrNum, quoteStr);
  73. }
  74.  
  75.  
  76. static pascal void
  77. DoLine (DialogPtr dlog, short item)
  78. {
  79. Rect    r;
  80.  
  81.     SkelGetDlogRect (dlog, item, &r);
  82.     FrameRect (&r);
  83. }
  84.  
  85.  
  86. /*
  87.  * Get the text of an item, and return true if it's different than
  88.  * the current value
  89.  */
  90.  
  91. static Boolean
  92. CheckDText (DialogPtr dlog, short item, StringPtr str)
  93. {
  94. Str255        tmpStr;
  95. Boolean        changed;
  96.  
  97.     SkelGetDlogStr (dlog, item, tmpStr);
  98.     changed = (CompareString (str, tmpStr) != 0);
  99.     CopyString (tmpStr, str);
  100.     return (changed);
  101. }
  102.  
  103.  
  104. static void
  105. SetParaCheck (DialogPtr dlog, Boolean each, Boolean blank, Boolean smart)
  106. {
  107.     SkelSetDlogCtlValue (dlog, paraEach, each);
  108.     SkelSetDlogCtlValue (dlog, paraBlank, blank);
  109.     SkelSetDlogCtlValue (dlog, paraSmart, smart);
  110. }
  111.  
  112.  
  113.  
  114. void
  115. DoParaDialog (void)
  116. {
  117. ModalFilterProcPtr    filter;
  118. DialogPtr    dlog;
  119. GrafPtr        tmpPort;
  120. short        itemHit = 0;
  121. Boolean        loop = true;
  122. short        hilite;
  123. Boolean        curEach, curBlank, curSmart;
  124. Boolean        changed;
  125. Str255        s;
  126.  
  127.     dlog = GetNewDialog (paraDlogNum, nil, (WindowPtr) -1L);
  128.     if (dlog == (DialogPtr) nil)
  129.     {
  130.         SysBeep (1);
  131.         return;
  132.     }
  133.  
  134.     SkelPositionWindow (dlog, skelPositionOnParentDevice,
  135.                                         FixRatio (1, 2), FixRatio (1, 5));
  136.  
  137.     GetPort (&tmpPort);
  138.     SetPort (dlog);
  139.  
  140.     SkelSetDlogButtonOutliner (dlog, outlineUserItem);
  141.  
  142.     SetParaCheck (dlog, curEach = paraStyle.pEachLine,
  143.                              curBlank = paraStyle.pBlankLine,
  144.                              curSmart = paraStyle.pSmartJoin);
  145.     SkelSetDlogStr (dlog, paraPText, periodStr);
  146.     SkelSetDlogStr (dlog, paraQText, quoteStr);
  147.     SkelSetDlogStr (dlog, paraMText, paraMark);
  148.     SkelSetDlogProc (dlog, paraLine1, DoLine);
  149.     SkelSetDlogProc (dlog, paraLine2, DoLine);
  150.  
  151.     ShowWindow (dlog);
  152.     InitCursor ();
  153.  
  154.     while (loop)
  155.     {
  156.         filter = SkelDlogFilter (nil, true);
  157.         SkelDlogCancelItem (paraCancel);
  158.         ModalDialog (filter, &itemHit);
  159.         SkelRmveDlogFilter ();
  160.  
  161.         switch (itemHit)
  162.         {
  163.  
  164.         case paraOK:
  165.             changed = (paraStyle.pEachLine != curEach);
  166.             paraStyle.pEachLine = curEach;
  167.  
  168.             changed |= (paraStyle.pBlankLine != curBlank);
  169.             paraStyle.pBlankLine = curBlank;
  170.  
  171.             changed |= (paraStyle.pSmartJoin != curSmart);
  172.             paraStyle.pSmartJoin = curSmart;
  173.  
  174.             changed |= CheckDText (dlog, paraMText, paraMark);
  175.             changed |= CheckDText (dlog, paraPText, periodStr);
  176.             changed |= CheckDText (dlog, paraQText, quoteStr);
  177.  
  178.             if (changed)
  179.                 mapModified = true;
  180.             loop = false;
  181.             break;
  182.  
  183.         case paraCancel:
  184.             loop = false;
  185.             break;
  186.  
  187.         case paraEach:
  188.             curEach = !curEach;
  189.             if (curEach)
  190.                 curBlank = false;
  191.             break;
  192.  
  193.         case paraBlank:
  194.             curBlank = !curBlank;
  195.             if (curBlank)
  196.                 curEach = false;
  197.             break;
  198.  
  199.         case paraSmart:
  200.             curSmart = !curSmart;
  201.             break;
  202.  
  203.         }
  204.         SetParaCheck (dlog, curEach, curBlank, curSmart);
  205.  
  206.         /*
  207.          * If smart join is selected but there aren't any sentence terminators,
  208.          * disable the OK button.
  209.          */
  210.         SkelGetDlogStr (dlog, paraPText, s);
  211.         hilite = (curSmart && s[0] == 0 ? dimHilite : normalHilite);
  212.         if (SkelSetDlogCtlHilite (dlog, paraOK, hilite))
  213.             SkelDrawButtonOutline (SkelGetDlogCtl (dlog, paraOK));
  214.     }
  215.     DisposeDialog (dlog);
  216.     SetPort (tmpPort);
  217. }
  218.